package com.wdb007.venus.svc.biz.manager;

import java.net.URI;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WebSocketChatClient extends WebSocketClient {

	private Logger logger = LoggerFactory.getLogger(WebSocketChatClient.class);

	private String data;

	public WebSocketChatClient(URI serverUri) {
		super(serverUri);
	}
	
	public WebSocketChatClient(URI serverUri, String data) {
		super(serverUri);
		this.data = data;
	}

	@Override
	public void onOpen(ServerHandshake handshakedata) {
		logger.info("onpen------");
		if(null != this.data) {
			send(data);
			close();
		}

	}

	@Override
	public void onMessage(String message) {
		logger.info("got: " + message);
	}

	@Override
	public void onClose(int code, String reason, boolean remote) {
		logger.info("onClose===============");
	}

	@Override
	public void onError(Exception ex) {
		logger.error("连接异常。。。。。", ex);
//		this.connect();
	}

}
